<!--

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<div class="title">
  <h1>Authentication</h1>
</div>

<mat-card class="identity-providers__form__card">
  <div class="title">
    <h3>Configuration</h3>
  </div>
  <form *ngIf="identityProvidersForm" [formGroup]="identityProvidersForm" autocomplete="off">
    <mat-card-content>
      <gio-form-slide-toggle
        [matTooltip]="'Configuration provided by the system'"
        [matTooltipDisabled]="!isReadonly('portal.authentication.forceLogin.enabled')"
        formGroupName="forceLogin"
        class="identity-providers__form__card__form-field"
      >
        <mat-icon *ngIf="isReadonly('portal.authentication.forceLogin.enabled')" gioFormPrefix>lock</mat-icon>
        <gio-form-label>Force authentication to access portal</gio-form-label>
        <mat-slide-toggle
          formControlName="enabled"
          gioFormSlideToggle
          aria-label="Force authentication to access portal"
        ></mat-slide-toggle>
      </gio-form-slide-toggle>
      <gio-form-slide-toggle
        [matTooltip]="'Configuration provided by the system'"
        [matTooltipDisabled]="!isReadonly('portal.authentication.localLogin.enabled')"
        formGroupName="localLogin"
        class="identity-providers__form__card__form-field"
      >
        <mat-icon *ngIf="isReadonly('portal.authentication.localLogin.enabled')" gioFormPrefix>lock</mat-icon>
        <gio-form-label>Show login form on portal</gio-form-label>
        <mat-slide-toggle formControlName="enabled" gioFormSlideToggle aria-label="Show login form on portal"></mat-slide-toggle>
      </gio-form-slide-toggle>
    </mat-card-content>
  </form>
  <gio-table-wrapper
    [filters]="initialFilters"
    [length]="identityProviderUnpaginatedLength"
    (filtersChange)="onPropertiesFiltersChanged($event)"
  >
    <table
      mat-table
      [dataSource]="filteredIdentityProviderSettingsTable"
      class="identity-providers__table"
      id="identityProviderTable"
      aria-label="Identity Provider table"
    >
      <ng-container matColumnDef="logo">
        <th mat-header-cell *matHeaderCellDef id="logo"></th>
        <td mat-cell *matCellDef="let element">
          <img class="identity-providers__table__logo" [src]="element.logo" alt="Logo of {{ element.name }}" />
        </td>
      </ng-container>
      <ng-container matColumnDef="id">
        <th mat-header-cell *matHeaderCellDef id="id">Id</th>
        <td mat-cell *matCellDef="let element">
          {{ element.id }}
        </td>
      </ng-container>
      <ng-container matColumnDef="name">
        <th mat-header-cell *matHeaderCellDef id="name">Name</th>
        <td mat-cell *matCellDef="let element">
          {{ element.name }}
        </td>
      </ng-container>
      <ng-container matColumnDef="description">
        <th mat-header-cell *matHeaderCellDef id="description">Description</th>
        <td mat-cell *matCellDef="let element">
          {{ element.description }}
        </td>
      </ng-container>
      <ng-container matColumnDef="actions">
        <th mat-header-cell *matHeaderCellDef id="actions">Actions</th>
        <td mat-cell *matCellDef="let element">
          <div class="identity-providers__table__centered-cell">
            <button
              *gioPermission="{ anyOf: ['environment-identity_provider_activation-u'] }"
              (click)="onActivationToggleActionClicked(element)"
              mat-icon-button
              aria-label="Identity provider activation"
              matTooltip="
            {{ element.isActivated ? 'Deactivate identity provider' : 'Activate identity provider' }}
            "
            >
              <mat-icon>{{ element.isActivated ? 'toggle_on' : 'toggle_off' }}</mat-icon>
            </button>
          </div>
        </td>
      </ng-container>

      <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
      <tr mat-row *matRowDef="let row; columns: displayedColumns"></tr>

      <!-- Row shown when there is no data -->
      <tr class="mat-mdc-row mdc-data-table__row" *matNoDataRow>
        <td *ngIf="!isLoadingData" class="mat-mdc-cell mdc-data-table__cell" [attr.colspan]="displayedColumns.length">
          {{ 'No notifications to display.' }}
        </td>
        <td *ngIf="isLoadingData" class="mat-cell" [attr.colspan]="displayedColumns.length">
          {{ 'Loading...' }}
        </td>
      </tr>
    </table>
  </gio-table-wrapper>
</mat-card>
<gio-save-bar [form]="identityProvidersForm" [formInitialValues]="formInitialValues" (submitted)="onSubmit()"></gio-save-bar>
